package com.cj.startup.simple

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.cj.startup.Startup
import com.cj.startup.event.StartupObserve
import com.cj.startup.manager.StartupManager
import com.cj.startup.simple.task.Task1
import com.cj.startup.simple.task.Task6
import com.cj.startup.simple.task.Task7

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        StartupManager.addFinishedObserver(mutableListOf(Task1::class.java,Task6::class.java),object :StartupObserve{
            override fun call(
                event: StartupObserve.Event,
                clazz: Class<out Startup<*>>?,
                result: Any?
            ) {
                println("---------------Finished-event:$event,clazz:$clazz,result:$result")
            }
        })

        StartupManager.addObserver(mutableListOf(Task7::class.java),object:StartupObserve{
            override fun call(
                event: StartupObserve.Event,
                clazz: Class<out Startup<*>>?,
                result: Any?
            ) {
                println("----------------event:$event,clazz:$clazz,result:$result")
                if(event == StartupObserve.Event.FINISHED){
                    StartupManager.removeObserver(this)
                }
            }

        })
        StartupManager.run(this,Task7()){
            println("-------------task7执行完毕，执行结果：$it")
        }

    }

}